<script setup lang="ts">
import type { ChannelResData, ChannelItem } from '../types/data'
import axios from 'axios'
import { ref } from 'vue'

const dataList = ref<ChannelItem[]>()
;(async () => {
  const res = await axios.get<ChannelResData>('http://geek.itheima.net/v1_0/channels')
  dataList.value = res.data.data.channels
})()

defineProps<{
  channelId: number
}>()

const emit = defineEmits<{
  (e: 'changeChannel', val: number): void
}>()
</script>

<template>
  <div class="channel-nav">
    <nav class="list">
      <a
        class="item"
        :class="{ active: channelId === item.id }"
        href="javascript:;"
        v-for="item in dataList"
        :key="item.id"
        @click="emit('changeChannel', item.id)"
      >
        {{ item.name }}
      </a>
    </nav>
  </div>
</template>
